Skip to content

Data Representation

Number systems

Alt text

Understand binary

  • Any form of data needs to be converted to binary to be processed by a computer.
  • The basic building block in all computers is the binary number system.

Switch

Switch ON is 1 and OFF is 0. Alt text

Alt text

Digit weight

  • Every one of us is used to the decimal or denary (base 10) number system. This uses the digits 0 to 9 which are placed in ‘weighted’ columns.
100001000100101
104103102101100
31421
  • Example: 3x10000 + 1x1000 + 4x100 + 2x10 + 1x1 = 31421

Binary to denary

  • Except for denary, we use binary(base 2) and hexadecimal(base 16) number system in the computer.
Denary value0123456789101112131415
Binary value0000000100100011010001010110011110001001101010111100110111101111
Hexadecimal value0123456789ABCDEF
  • The binary system uses 1s and 0s only which gives these corresponding weightings.
  • We can convert binary number to denary according to digit weightings.
1286432168421
2726252423222120
11101110
  • Example: 1110 11102 = 128 + 64 + 32 + 8 + 4 + 2 = 23810

2 to 10

Convert binary to denary: 0011 0011 ?

[0/1]
binary
number system

2 to 10

Which number is closest to 0011 1111 ?

[0/1]

2 to 10

Which numbers are less than 1011 1101 ?

[0/1]

Hexadecimal to denary

  • The hexadecimal system is very closely related to the binary system.
  • Hexadecimal is a base 16 system.
  • Because it is a system based on 16 different digits, the numbers 0 to 9 and the letters A to F are used to represent hexadecimal digits.
  • A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.
  • We can convert hexadecimal number to denary according to digit weightings.
655364096256161
164163162161160
01123

Example: 0112316 = 1x4096 + 1x256 + 2x16 + 3x1 = 438710

16 to 10

Convert hexadecimal to denary: ABC ?

[0/1]

16 to 10

Convert hexadecimal to denary: DE0 ?

[0/1]

Use of the hexadecimal system

When the memory contents are output to a printer or monitor, this is known as a memory dump.

Alt text

Denary to binary

  • Converting from denary to binary is slightly more complex.
  • This method involves successive division by 2 until the result is 0; the remainders are then written from bottom to top to give the binary value.
DividerResultRemainderProcess
2107
2531107 ➗ 2 = 53 ……1
226153 ➗ 2 = 26 ……1
213026 ➗ 2 = 13 ……0
26113 ➗ 2 = 6 ……1
2306 ➗ 2 = 3 ……0
2113 ➗ 2 = 1 ……1
011 ➗ 2 = 0 ……1
  • Example: 10710 = 110 10112

10 to 2

Convert denary to binary: 41 ?

[0/1]

10 to 2

Convert denary to binary: 252 ?

[0/1]

Denary to hexadecimal

  • Converting from denary to hexadecimal is slightly similar with denary to binary.
  • This method involves successive division by 16; the remainders are then written from bottom to top to give the hexadecimal value.
DividerResultRemainderProcess
162004
1612542004 ➗ 16 = 125 ……4
16713(D)125 ➗ 16 = 7 ……13(D)
16077 ➗ 16 = 0 ……7
  • Example: 200410 = 7D416

10 to 16

Convert denary to hexadecimal: 2022 ?

[0/1]

10 to 16

Convert denary to hexadecimal: 252 ?

[0/1]

Binary to hexadecimal

  • Since 16 = 24, four binary digits are equivalent to each hexadecimal digit.
Binary value0000000100100011010001010110011110001001101010111100110111101111
Hexadecimal value0123456789ABCDEF
Denary value0123456789101112131415
  • Example: 11111000012 = 0011 1110 00012 = 3E116

2 to 16

Convert binary to hexadecimal: 1001011 ?

[0/1]

Hexadecimal to binary

  • Since 16 = 24, one hexadecimal digit are equivalent to four binary digits.

  • Example: 45A16 = 0100 0101 10102

16 to 2

Convert hexadecimal to binary: 6C ?

[0/1]

Positive numbers in binary

  • There are two methods to represent both positive and negative numbers.
  • In one’s complement, each digit in the binary number is inverted.
  • In two’s complement, each digit in the binary number is inverted and a ‘1’ is added to the right-most bit.

Alt text

Decimal valueTwo's-complement representation
00000 0000
10000 0001
20000 0010
1260111 1110
1270111 1111
−1281000 0000
−1271000 0001
−1261000 0010
−21111 1110
−11111 1111

Two’s complement

  • The two’s complement uses these weightings for an 8-bit number representation.
-1286432168421
10401101000
-10410011000
  • For example, 104 in binary is 0 1 1 0 1 0 0 0.
  • To find the binary value for −104 using two’s complement:
  • Invert the digits: 1 0 0 1 0 1 1 1 (+104 in denary)
  • Add 1: 1
  • Which gives: 1 0 0 1 1 0 0 0 (−104 in denary)

Two's complement

Use two's complement to represent -114 with 8 bits.

[0/1]

Binary addition

bianry addtion

  • 0 + 0 = 0
  • 1 + 0 = 1 (sum 1 and carry 0)
  • 1 + 1 = 10 (sum 0 and carry 1 )
  • 1 + 1 + (carry 1) = 11= sum 1 and carry 1
  • Add 0 0 1 0 0 1 0 1 (37 in denary) and 0 0 1 1 1 0 1 0 (58 in denary).
-1286432168421
3700100101
+
5800111010
=
Carry01000000
Sum01011111
  • The sum is 0101 1111, which is 95 in denary.

Binary addition

Calculate 0011 1001 + 0010 1001.

[0/1]

Binary subtraction

  • Carry out the subtraction 95 – 68 in binary.
-1286432168421
9501011111
-
6801000100
-6810111100
Carry1 (Drop it)11111000
Sum1 (Drop it)00011011
  • The result is 0001 1011, which is 27 in denary.

Binary subtraction

Calculate 0110 0011 - 0011 0000.

[0/1]

Overflow error

  • Add 0 1 0 1 0 0 1 0 (82 in denary) and 0 1 0 0 0 1 0 1 (69 in denary).
-1286432168421
8201010010
+
6901000101
=
Carry10000000
Sum10010111
  • The sum is 1001 0111, which is -105 (Incorrect)

Overflow error

  • The expected answer for 82 + 69 is 151, which is out of range for the 8 bits register (-128~127), this is known as an overflow error.

Logical shifts

  • The positive binary integer is multiplied or divided according to the shift performed.
  • Bits shifted from the end of the register are lost and zeros are shifted in at the opposite end of the register.
  • The most significant bit(s) or least significant bit(s) are lost.

Alt text

Logical shift

Right shift 1011 0101 with 2 digits?

[0/1]

Measurement of the size of computer memories

TIP

A binary digit is referred to as a BIT. 4 bits are 1 NIBBLE. 8 bits are 1 BYTE.

Storage Device

MeasurementNumber of bytes
1 kilobyte(1 KB)103
1 megabyte(1 MB)106
1 gigabyte(1 GB)109
1 terabyte(1 TB)1012
1 petabyte(1 PB)1015

Computer System

MeasurementNumber of bytes
1 kibibyte(1 KiB)210
1 mebibyte(1 MiB)220
1 gibibyte(1 GiB)230
1 tebibyte(1 TiB)240
1 pebibyte(1 PiB)250

KB vs KiB

  • KB is used in factory and Kib is used in computer system.

Memory size

8GB = ( ) bits?

[0/1]

Memory size

8GiB = ( ) bytes?

[0/1]

Binary-coded decimal (BCD) system

  • The binary-coded decimal (BCD) system uses a 4-bit code to represent each denary digit.
0 0 0 000 1 0 15
0 0 0 110 1 1 06
0 0 1 020 1 1 17
0 0 1 131 0 0 08
0 1 0 041 0 0 19
  • Therefore, the denary number 3 1 6 5 would be 0011 0001 0110 0101 in BCD format.

Use of BCD

  • The most obvious use of BCD is in the representation of digits on a calculator or clock display.

Alt text

  • Consider adding $0.37 and $0.94 together using fixed-point decimals.

Alt text

Alt text

BCD

Convert denary number 271 to BCD format?

[0/1]

ASCII codes and Unicodes

  • ASCII (American Standard Code for Information Interchange)

Text is converted to binary to be processed by a computer according to ASCII code.(7 bits per character).

Extended ASCII code

  • Extended ASCII code use 8 bits per character.

  • A is stored as 0100 0001

ASCII code

DECOCTHEXBINSymbolHTML NumberDescription
651014101000001AAUppercase A
661024201000010BBUppercase B
671034301000011CCUppercase C
681044401000100DDUppercase D
691054501000101EEUppercase E
701064601000110FFUppercase F

Unicode

  • Unicode allows for a greater range of characters and symbols than ASCII, including different languages and emojis. (16 bits per character)

Alt text

ASCII

If A is stored as 65 in ASCII code, what is the binary value to store G?

[0/1]

Hexa use

Which items are using hexadecimal?

[0/1]